﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WP7Client.Helpers;
using WP7Client.ServerManager;
using GalaSoft.MvvmLight.Command;
using MSH.Common.DAO.Results;
using MSH.Common.Classes;
using WP7Client.UserInterface.Pages;
using MSH.Common.DAO;
using WP7Client.Managers;

namespace WP7Client.Controller
{
    public class OverviewController : BaseController
    {
        private String status;
        public OverviewPage OverviewPage;

        public OverviewController()
        {
            ApplyStatusCommand = new RelayCommand(ApplyStatus);
            String status = (String)IsolatedStorageHelper.GetData(UserHelper.Username + ".Status");
            if (!String.IsNullOrEmpty(status))
                Status = status;
            else
            {
                Status = "Just installed MSH!";
                ApplyStatus();
            }
        }

        public ICommand ApplyStatusCommand
        {
            get;
            internal set;
        }

        public override void Update()
        {
            base.Update();
        }

        public String Status
        {
            get { return status; }
            set { status = value; OnPropertyChanged("Status"); }
        }

        private UserLocationData currentLocation;
        public UserLocationData CurrentLocation
        {
            get { return currentLocation; }
            set { currentLocation = value; OnPropertyChanged("CurrentLocation"); }
        }

        public Boolean IsConnected
        {
            get { return GlobalHelper.IsConnected; }
            set { GlobalHelper.IsConnected = value; OnPropertyChanged("IsConnected"); }
        }

        private String peopleNearbyCount = "(0)";
        public String PeopleNearbyCount
        {
            get { return peopleNearbyCount; }
            set { peopleNearbyCount = value; OnPropertyChanged("PeopleNearbyCount"); }
        }

        /// <summary>
        /// Update je status tekst
        /// </summary>
        private void ApplyStatus()
        {
            IsolatedStorageHelper.SetData((UserHelper.Username + ".Status"), Status);
            HttpGet applyStatusHttpGet = new HttpGet(GlobalHelper.Url + String.Format("SetStatus/{0}/{1}", UserHelper.Token, Status), typeof(SetStatusResult));
        }

        /// <summary>
        /// Opvragen of er ongelezen berichten zijn
        /// </summary>
        public Boolean GotNewUnreadMessages
        {
            get
            {
                if (ControllerHelper.ConversationsController != null)
                    return ControllerHelper.ConversationsController.AreThereUnreadMessages;
                else
                    return false;
            }
            set
            {

            }
        }
    }
}
